<template>
  <div class="subtitle-display" @click="handleSubtitleClick">
    <div
      v-if="currentSubtitle"
      class="subtitle-text"
      :class="{ clickable: hasWords }"
      v-html="highlightedSubtitle"
    ></div>
    <div v-else class="no-subtitle">暂无字幕</div>
  </div>
</template>

<script>
export default {
  name: 'SubtitleDisplay',
  props: {
    subtitle: {
      type: Object,
      default: null,
    },
    currentTime: {
      type: Number,
      default: 0,
    },
  },
  data() {
    return {
      selectedWord: null,
    };
  },
  computed: {
    currentSubtitle() {
      return this.subtitle;
    },
    hasWords() {
      if (!this.currentSubtitle) return false;
      // Check if subtitle text contains English words
      return /[a-zA-Z]+/.test(this.currentSubtitle.text);
    },
    highlightedSubtitle() {
      if (!this.currentSubtitle) return '';

      // For now, just return the text as is
      // In a more advanced implementation, we could highlight specific words
      return this.currentSubtitle.text.replace(/\n/g, '<br>');
    },
  },
  methods: {
    handleSubtitleClick(time, text) {
      console.log('Clicked subtitle:', time, text);
      this.$emit('subtitle-click', { time, text });
    },
  },
};
</script>

<style scoped>
.subtitle-display {
  padding: 20px;
  text-align: center;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.7);
  color: white;
  border-radius: 8px;
  margin: 10px 0;
  cursor: default;
}

.subtitle-text {
  font-size: 20px;
  line-height: 1.4;
  max-width: 100%;
  word-wrap: break-word;
}

.subtitle-text.clickable {
  cursor: pointer;
}

.subtitle-text.clickable:hover {
  background-color: rgba(255, 255, 255, 0.1);
}

.no-subtitle {
  color: #999;
  font-style: italic;
}
</style>
